package com.bnz.controller;

import cn.hutool.core.util.StrUtil;
import com.bnz.entity.Student;
import com.bnz.service.StudentService;
import com.bnz.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/student")
public class StudentController  extends HttpServlet {
    private StudentService studentService;


    public void init() throws ServletException {
        studentService = new StudentServiceImpl();
    }
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        req.setCharacterEncoding("utf-8");

      this.list(req,resp);
    }
    private void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //2.1 得到所有的学生列表
        List<Student> students = studentService.findAll();
        //2.2 将学生列表放到请求作用域中
        req.setAttribute("students",students);
        //2.3 进行页面跳转
        req.getRequestDispatcher("/WEB-INF/jsp/student/list.jsp").forward(req,resp);
    }
}
